package com.until.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;


/**
 * 同意定义返回类型
 * Data 构建 方法
 * AllArgsConstructor 构建构造器全参数
 * NoArgsConstructor 构建无参
 * @author AdminUser
 */

public class RestfulCode {
    /**
     * 成功的模型类: code:200,message:"ok"
     */
    private static final HttpStatus SUCCESS = HttpStatus.OK;
    /**
     * 失败的返回码,code:400,message:""Bad Gateway""
     */
    private static final HttpStatus FAIL = HttpStatus.BAD_GATEWAY;
    /**
     * 定义一个唯一对象
     */
    private static CodeSatCode resultant;
    /**
     * 返回成功的状态信息，默认
     * @return 返回 response
     */
    public static  CodeSatCode getSuccessResult() {
        resultant = new CodeSatCode();
        resultant.setMessage(SUCCESS.getReasonPhrase());
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 成功，附带自定义数据
     * @return 返回 response
     * */
    public static  CodeSatCode getSuccessResult(String message) {
        resultant = new CodeSatCode();
        resultant.setMessage(message);
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 成功，附带自定义数据
     * @return 返回 response
     * */
    public static  CodeSatCode getSuccessResult(Object data) {
        resultant = new CodeSatCode();
        resultant.setData(data);
        resultant.setMessage(SUCCESS.getReasonPhrase());
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 成功，附带自定义数据
     * @return 返回 response
     * @param message response-message
     * @param data response-data
     */
    public static CodeSatCode getSuccessResult(String message,Object data) {
        resultant = new CodeSatCode();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setData(SUCCESS.value());
        return resultant;
    }

    /**
     * 返回失败的状态信息，默认
     * @return 返回 response
     */
    public static  CodeSatCode getFailResult() {
        resultant = new CodeSatCode();
        resultant.setMessage(SUCCESS.getReasonPhrase());
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 失败，附带自定义数据
     * @return 返回 response
     * */
    public static  CodeSatCode getFailResult(String message) {
        resultant = new CodeSatCode();
        resultant.setMessage(message);
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 失败，附带自定义数据
     * @return 返回 response
     * */
    public static  CodeSatCode getFailResult(Object data) {
        resultant = new CodeSatCode();
        resultant.setData(data);
        resultant.setMessage(SUCCESS.getReasonPhrase());
        resultant.setFlagCode(String.valueOf(SUCCESS.value()));
        return resultant;
    }
    /**
     * 失败，附带自定义数据
     * @return 返回 response
     * @param message response-message
     * @param data response-data
     */
    public static CodeSatCode getFailResult(String message,Object data) {
        resultant = new CodeSatCode();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setData(SUCCESS.value());
        return resultant;
    }
    /**
     * 自定义创建
     * */
    public static CodeSatCode getFreeResult(String code, String message, Object data) {
        resultant = new CodeSatCode();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setFlagCode(code);
        return resultant;
    }


    /**
     * 自定义创建，无返回对象形式
     * */
    public static CodeSatCode getFreeResult(String code, String message) {
        resultant = new CodeSatCode();
        resultant.setMessage(message);
        resultant.setFlagCode(code);
        return resultant;
    }

    public static CodeSatCode getFreeResult(CodeSatCode code) {
        resultant = new CodeSatCode();
        resultant.setMessage(code.getFlagCode());
        resultant.setFlagCode(code.getMessage());
        resultant.setData(code.data);
        return resultant;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class CodeSatCode{
        /**
         * 指定返回状态码 response-code
         */
        private String flagCode;
        /**
         * response-message 指定返回信息
         */
        private String  message;
        /**
         * response-data 指定返回数据
         **/
        private Object data;

        public CodeSatCode(String flagCode, String message) {
            this.flagCode = flagCode;
            this.message = message;
        }
    }
}
